<?php

namespace App\Models;

use Encore\Admin\Form;
use Encore\Admin\Grid;
use Illuminate\Database\Eloquent\Model;
use Spatie\EloquentSortable\Sortable;
use Spatie\EloquentSortable\SortableTrait;


use Encore\Admin\Traits\AdminBuilder;
use Encore\Admin\Traits\ModelTree;
use Illuminate\Support\Facades\DB;


class City extends Model
{
	 use AdminBuilder, ModelTree {
        ModelTree::boot as treeBoot;
    }
	 public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);

        $this->setParentColumn('parent_id');
        $this->setOrderColumn('id');
        $this->setTitleColumn('name');
    }
    //
    protected $table = 'city';
	public static function boot()
	{
	    parent::boot();
	    static::saving(function ($model) {
	        if(empty($model['parent_id'])){
	        	$model['parent_id']=0;
	        }
	    });
		static::deleting(function(){
		});
	}
}
